#!/bin/bash
# login bash

echo -n "Please input your username:"
read name
echo -n "Password:"
stty -echo
read pwd
stty echo
info="$(date) on $(tty)"
lastf="Last failed login: $(tail -n 1 loginerr.log)"
lastl="Last login: $(tail -n 1 login.log)"
core="$(uname -r)"
if [ $name = "tom" ]
then
        if [ $pwd = "tom" ]
        then
                echo -e "$info" >> login.log
		echo -e "\n$lastf"
		echo -e "$lastl"
		echo -e "\nWelcome to $core"
		$(sed -i '$d' loginerr.log)
        else
                echo "Password wrong!"
                echo -e "$info" >> loginerr.log
		read
        fi
else
        echo -e "\nuser $name not exists"
        echo -e "$info" >> loginerr.log
        read
fi
